﻿@{
    ViewBag.Title = "登录";
}

<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="~/Content/style.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.8.2.min.js"></script> 
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <title>登录后台</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3 login">
                <h3>登录后台</h3>
                <form class="form-inline" method="post"> 
                    <div class="form-group">
                        <label for="user">帐号：</label>
                        <input type="text" class="form-control" id="name" name="user" placeholder="用户" value="admin">
                    </div>
                    <div class="form-group">
                        <label for="passwd">密码：</label>
                        <input type="password" class="form-control" id="passwd" name="passwd" placeholder="密码" value="admin123">
                    </div>
                       <div class="form-group" style="width:263.83px; text-align:right;">
                            <img  id="imgCode" onclick="refImg()"/> &nbsp;&nbsp;&nbsp;&nbsp;
                           <label for="veriCode"><a onclick="refImg()" style="color:blue;text-decoration:none">刷新验证码</a></label>
                        </div>
                     <div class="form-group" style="width:263.83px; text-align:right;"> 
                        <input type="text" class="form-control"  id="veriCode" name="veriCode" placeholder="请输入左侧验证码">
                    </div>
                 
                    <div class="clearfix"></div>
                    <button type="button" class="btn btn-primary" onclick="login()">登录</button>
                </form>

            </div>
        </div>
    </div>
</body>

<script> 
    refImg();
    function refImg() {
       
        var img = new Image();
        img.src = "/Manager/login/getimg?t=" + Math.random();
        img.onload = function () { //图片
            $("#imgCode").attr("src", img.src);
            //test
            $.ajax({
                url: "/manager/Login/GetCode",
                type: "get", 
                contentType: "application/json",
                success: function (result) {
                    $("#veriCode").val(result);
                }
            });
        }
    }
    function login() {
        
        var usersParams = {};
        usersParams.Name = $("#name").val();
        usersParams.Pwd = $("#passwd").val();
        $.ajax({
            url: "/manager/Login/Login",
            type: "POST",
            data: JSON.stringify(usersParams),
            contentType: "application/json",
            success: function (result) {
                if (result == "1") {
                    location.href = "/Manager/menu";
                }
                else
                {
                    alert("登录失败，请输入正确的帐号和密码。");
                }
            }
        });
    }
</script>
</html>
